package com.culturalCenter.dataCenter.service.impl.user;

import com.culturalCenter.dataCenter.customEntity.responseParam.user.UserFootprintListResponse;
import com.culturalCenter.dataCenter.entity.user.UserFootprint;
import com.culturalCenter.dataCenter.mapper.user.UserFootprintMapper;
import com.culturalCenter.dataCenter.service.user.UserFootprintService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/****
 * @Author:
 * @Description:UserFootprint业务层接口实现类
 * @Date
 *****/
@Service
public class UserFootprintServiceImpl implements UserFootprintService {

    @Resource
    private UserFootprintMapper userFootprintMapper;

    @Override
    public PageInfo<UserFootprint> findPage(int page, int size) {
        return PageHelper.startPage(page, size).doSelectPageInfo(() -> userFootprintMapper.findPageAll());
    }

    @Override
    public Integer delete(String id) {
        return userFootprintMapper.deleteById(id);
    }

    @Override
    public Integer update(UserFootprint userFootprint) {
        return userFootprintMapper.update(userFootprint);
    }

    @Override
    public Integer add(UserFootprint userFootprint) {
        return userFootprintMapper.insert(userFootprint);
    }

    @Override
    public UserFootprint findById(String id) {
        return userFootprintMapper.queryById(id);
    }

    @Override
    public List<UserFootprint> findAll(UserFootprint userFootprint) {
        return (List<UserFootprint>) userFootprintMapper.queryAll(userFootprint);
    }

    @Override
    public PageInfo<UserFootprintListResponse> findFootprintList(String userId, int pageNum, int pageSize) {
        List<UserFootprintListResponse> userFootprintListResponseList = new ArrayList<>();
        List<String> dateList = userFootprintMapper.findDateList(userId, (pageNum - 1) * pageSize, pageSize);
        if (dateList.size() > 0) {
            for (String date : dateList) {
                List<UserFootprint> userFootprintList = userFootprintMapper.findListByUserAndDate(userId, date);
                userFootprintListResponseList.add(new UserFootprintListResponse(date, userFootprintList));
            }
        }
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(userFootprintListResponseList);
    }

}
